#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif
#include "CommonTool.h"

using namespace SystemTool;

// Get current process id
int CommonTool::GetCurProcessId()
{
#ifdef _WIN32
	return GetCurrentProcessId();
#else
#include <unistd.h>
	return getpid();
#endif
}

// Get current thread id
int CommonTool::GetCurThreadID()
{
#ifdef _WIN32
	return GetCurrentThreadId();
#else
#include <unistd.h>
	return gettid();
#endif
}

// Split the string
bool CommonTool::Split(std::string strData, std::string strSeperator, std::vector<std::string>& vTable)
{
	if (strData.empty())
	{
		return false;
	}

	if (strSeperator.empty())
	{
		return false;
	}

	int iPos = strData.find(strSeperator);

	if (iPos == -1)
	{
		return false;
	}

	std::string strTempData = strData;

	while ((iPos = strTempData.find(strSeperator)) != -1)
	{
		std::string strPieceData = strTempData.substr(0, iPos);

		vTable.push_back(strPieceData);

		strTempData = strTempData.substr(iPos + strSeperator.length());
	}

	if (!strTempData.empty())
	{
		vTable.push_back(strTempData);
	}
	
	return true;
}
